<template>
	<view class="my-path">
		<view class="path-list">
			
			
			
			<view  v-for="(item,index) in list" :key="index" @tap="goToIndexPath(index)">
			
			<view class="path-item" @tap="goToOrder(item)">
				
				<view class="path-main">
					<view class="path-name">{{item.name}}</view>
					<view>{{item.tel}}</view>
				</view>
				<view class="path-main">
					<view class="active" v-if="item.isDefault == 1">默认</view>
					<view class="path-text">{{item.province}} {{item.city}} {{item.district}} {{item.address}}</view>
				</view>
			</view>
			
		</view>
			
			
			
		</view>
	
		<view class="add-path">
			<view class="add-path-bth" @tap="goToAdd">新增地址</view>
		</view>

	</view>
</template>

<script>
import $http from "@/common/api/request.js"
import {mapState,mapMutations} from 'vuex'
	export default {
		data() {
			return {
				isPath:false
			}
		},
	     onLoad(e) {
	     	if(e.type==="selectPath"){
	             this.isPath=true
			}
			this._initAddress()
	     },

		methods: {
			...mapMutations(['init']),
			_initAddress(){
				$http.request({
					url: "/selectAddress",
					method: "POST",
				    header:{
						token:true
					}
				}).then((res) => {
				   this.init(res.data)
				}).catch(() => {})
			},
			goToIndexPath(index){
				let pathObj =JSON.stringify({
					index:index,
					item:this.list[index]
				});
				
				uni.navigateTo({
					url:'/pages/my-add-path/my-add-path?data='+pathObj+''
				})
				
			},
			goToAdd(){
				uni.navigateTo({
					url:'/pages/my-add-path/my-add-path'
				})
			},
			goToOrder(item){
				if(this.isPath){
					uni.$emit("selectPathItem",item);
				     uni.navigateBack({
						 delta:1
					 })
					 
				}
			}
			
		},
		computed:{
			...mapState({
				list:sate=>sate.path.list
			})
		}
	}
</script>

<style scoped>
	.add-path{
		width: 100%;
		display: flex;
		justify-content: center;
		padding: 20rpx 0;
	}
	.add-path-bth{
		border: 2rpx solid #49BDFB;
		color: #49BDFB;
		border-radius: 30rpx;
		padding: 6rpx 60rpx;
	}
/* 	.add-path-bth:hover{
		background-color: #49BDFB;
		color: #f7f7f7;
	} */
	.path-list{
		 padding-left: 20rpx;
	}
	.path-item{
		padding: 10rpx;
		border-bottom: 2rpx solid #f7f7f7;
	}
	.path-main{
		display: flex;
		align-items: center;
	}
	.path-name{
		padding-right: 10rpx;
	}
	.active{
		padding :0 5rpx;
		background-color: #49BDFB;
		color: white;
		text-align: center;
		border-radius: 60rpx;
		font-size: 24rpx;
	}
	.path-text{
		padding-left: 40rpx;
	}
</style>
